const inquirer = require("inquirer");
const chalk = require("chalk");
const figlet = require("figlet");
const shell = require("shelljs");
const program = require("commander")
import vm from 'vm'

program.version("1.0.0")
  .usage("mycli")
  .command("init", "初始")
  .command("g", "自动")
  .command("query")
  .description("翻译")
  .action(async (obj: any) => {
    // inquirer.prompt([
    //   {
    //     name: "FILENAME",
    //     type: "input",
    //     message: "What is the name of the file without extension?"
    //   },
    //   {
    //     type: "list",
    //     name: "EXTENSION",
    //     message: "What is the file extension?",
    //     choices: [".rb", ".js", ".php", ".css"],
    //     filter: function(val: any) {
    //       return val.split(".")[1];
    //     }
    //   }
    // ]).then((res: any) => {
    //   console.log(chalk.green("extension is ", res))
    // })
    let context: Record<string, any> = {}
    vm.createContext(context);
    while (true) {
      let res = await inquirer.prompt([
        { name: 'cmd', 
          type: 'input'}
      ])
      let {cmd} = res
      try {
        let runLog = vm.runInContext(cmd, context)
        console.log(runLog)
      } catch (error) {
        console.log(chalk.red(error))        
      }
    }
  })
  .parse(process.argv)



// var questions = [
//   {
//     type: 'editor',
//     name: 'bio',
//     message: 'Please write a short bio of at least 3 lines.',
//     validate: function (text: any) {
//       if (text.split('\n').length < 3) {
//         return 'Must be at least 3 lines.';
//       }

//       return true;
//     },
//   },
// ];

// inquirer.prompt(questions).then((answers: any) => {
//   console.log(JSON.stringify(answers, null, '  '));
// });